package cn.stronglink.assetmanage.utils;

import android.widget.Spinner;
import android.widget.SpinnerAdapter;

/**
 * Created by chencongcong on 2018/6/25.
 */

public class SpinnerShowUtil {

    /**
     * 根据值, 设置spinner默认选中:
     * @param spinner
     * @param value
     */
    public static void setSpinnerItemSelectedByValue(Spinner spinner, String value){
        if (value==null)return;
        SpinnerAdapter apsAdapter= spinner.getAdapter(); //得到SpinnerAdapter对象
        int k= apsAdapter.getCount();
        for(int i=0;i<k;i++){
            if(value.equals(apsAdapter.getItem(i).toString())){
                spinner.setSelection(i,true);// 默认选中项
                break;
            }
        }
    }

}
